<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML>
<html>
<head>
    <title>文章列表</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-easyui/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/cyUtil.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/cyEasyUi.js"></script>
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/js/jquery-easyui/themes/default/easyui.css"
          type="text/css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/js/jquery-easyui/themes/icon.css"
          type="text/css"/>

    <script type="text/javascript">
        $(function(){
            $("#list_article_dataGrid").datagrid({
                fit : true,
                border : false,
                fitColumns : true,
                pagination : true,
                pagePosition : 'bottom',
                pageSize : 15,
                pageList : [ 10, 15, 20 ],
                idField : 'id',
                singleSelect:true,
                rownumbers:true,
                url : '${pageContext.request.contextPath}/article/article_loadArticle.action',
                columns : [[{
                    field : "id",
                    title : "编号",
                    width : 20,
                    hidden:true
                },{
                    field : "title",
                    title : "标题",
                    width : 50,
                    resizable : true
                },{
                    field : "overview",
                    title : "文章概要",
                    width : 50,
                    resizable : true
                },{
                    field : "classifyname",
                    title : "分类",
                    width : 50,
                    resizable : true
                },{
                    field : "releasetime",
                    title : "发布时间",
                    width : 50,
                    resizable : true
                },{
                    field : "filename",
                    title : "图片",
                    width : 50,
                    resizable : true
                },{
                    field : "support",
                    title : "点赞",
                    width : 50,
                    resizable : true
                },{
                    field : "views",
                    title : "浏览量",
                    width : 50,
                    resizable : true
                },{
                    field : "state",
                    title : "状态",
                    width : 30,
                    formatter:function(value){
                        if(value >= 1){
                            return "已发布";
                        }else{
                            return "未发布";
                        }
                    }
                },{
                    title:"操作",
                    field:"action",
                    width:90,
                    formatter:function(value,row){
                        var str = "";
                        str += formatString("<button type='button' onclick=\"editFun('{0}','{1}')\">{2}</button>", row.id,row.title,"修改");
                        str += formatString("<button type='button' onclick=\"deleteFun('{0}')\">{1}</button>", row.id,"删除");
                        str += formatString("<button type='button' onclick=\"toTopFun('{0}','{1}')\">{2}</button>", row.id, row.state, retname(row.state));
                        return str;
                    }
                }]]
            })
        });

        function retname(value){
           if(value == 2){
               return "取消置顶";
           }else if(value == 1){
               return "置顶";
           }else if(value == 0){
               return "发布";
           }
        }

        function searchFun(){
            $('#list_article_dataGrid').datagrid('load', serializeObject($("#list_article_searchForm")));
        }

        function cleanFun(){
            $('#list_article_layout input[name=title]').val('');
            $('#list_article_dataGrid').datagrid('load', {});
        }

        function editFun(id,title){
            var url = encodeURI("${pageContext.request.contextPath}/article/article_toEditArticle.action?id=" + id);
            window.parent.window.addTab({title:title,content:'<iframe src="${pageContext.request.contextPath}'+ url +'" frameborder="0" style="border:0;width:100%;height:98%;"></iframe>',closable:true});
        }

        function deleteFun(id){
            $.messager.confirm("确认","您是否要删除当前选中的条目?",function(r){
                 if(r){
                     $.ajax({
                         url:"${pageContext.request.contextPath}/article/article_remove.action",
                         data:{id : id},
                         dataType : "json",
                         success : function(obj) {
                             if (obj.success) {
                                 $("#list_article_dataGrid").datagrid("load");
                             }
                             $.messager.show({
                                 title : "提示",
                                 msg: obj.msg
                             });
                         }
                     });
                 }
            });

        }

        function toTopFun(id,state){
            $.ajax({
                url:"${pageContext.request.contextPath}/article/article_top.action",
                data:{id : id, state : state},
                dataType : "json",
                success : function(obj) {
                    if (obj.success) {
                        $("#list_article_dataGrid").datagrid("load");
                    }
                    $.messager.show({
                        title : "提示",
                        msg: obj.msg
                    });
                }
            });
        }
    </script>
</head>
<body>
<div id="list_article_layout" class="easyui-layout" data-options="fit:true">
    <div data-options="region:'north',border:false" style="margin-top: 10px; height: 30px;">
        <form id="list_article_searchForm">
            标题:
            <input type="text" name="title"/>
            分类:
            <input type="text" name="classifyname"/>
            搜索发布时间于:
            <input name="startdate" type="text" class="easyui-datetimebox">
            ~
            <input name="enddate" type="text" class="easyui-datetimebox">

            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="searchFun();">搜索</a>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true" onclick="cleanFun();">清空</a>
        </form>
    </div>

    <div data-options="region:'center',border:false">
        <table id="list_article_dataGrid"></table>
    </div>
</div>
</body>
</html>
